<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
    	$question = D('Vercode')->getOneVerify();
    	$this->assign('question',$question);
        $this->assign('title','登录');
        $this->display();
    }

    public function checkData()
    {
    	if (I('post.vercode') !=$_SESSION['answer']) {
    		$arr = array(
    			'error'=>1,
    			'info'=>"人类验证失败"
    			);
    		echo json_encode($arr);
    		exit;
    	}

    	
    if ($res = D('user')->checkPass(md5(I('post.pass')),I('post.email'))) {

            $res=current($res);
            // var_dump($res['id']);
            $_SESSION['id']=$res['id'];
            // $_SESSION['sex']=$res['sex'];
            $_SESSION['username']=$res['username'];
            // $_SESSION['email']=$res['email'];
            $_SESSION['headface']=$res['headface'];


    	$arr = array(
	   		'error'=>0,
	   		'info'=>"登录成功"
	   		);
	   	echo json_encode($arr);
	   	exit;
    }else{
    	$arr = array(
	   		'error'=>1,
	   		'info'=>"密码错误"
	   		);
	   	echo json_encode($arr);
	   	exit;
    }
    	$arr = array(
	    			'error'=>1,
	    			'info'=>"该账户不存在"
	    			);
	    		echo json_encode($arr);
	    		exit;
    }

    public function loginOut()
    {
        session_unset();
        session_destroy();
        // header("Location: ".U('home/index/index')); 

        $this->success("退出成功",U('home/index/index'),0);
    }











}